﻿using System;
using System.Collections.Generic;
using PredatorPrey.Library;
using PredatorPrey.Library.Algorithms;

namespace PredatorPrey
{
	// Id		: $Id: Search.cs 39 2009-04-23 21:38:07Z kristof@kristofmattei.be $
	// Date		: $Date: 2009-04-23 21:38:07 +0000 (Thu, 23 Apr 2009) $
	// Author	: $Author: kristof@kristofmattei.be $
	// Revision	: $Revision: 39 $
	/// <summary>
	/// The main 'real' class, which does actually everything 
	/// </summary>
	class Search
	{
		/// <summary>
		/// The Field 
		/// </summary>
		private Field field;

		public Search(Field field)
		{
			if (field == null)
			{
				throw new ArgumentNullException("Field cannot be null");
			}

			this.field = field;
		}

		/// <summary>
		/// Search the answer to life!
		/// Actually just the shortest, lowest cost path to the prey!
		/// </summary>
		public void StartSearch()
		{
			AStarSearch aStarSearch = new AStarSearch(this.field);

			//since this is not a generic package we hardcode what the start and goal types are (yes I am lazy).
			Cell start = this.field.SearchFor(FieldType.Predator);
			Cell goal = this.field.SearchFor(FieldType.Prey);


			List<Cell> points = aStarSearch.SearchPath(start, goal);

			//foreach (Cell item in points)
			//{
			//    System.Console.WriteLine(item);
			//}
			points.ForEach((Cell item) => System.Console.WriteLine(item));
			
			System.Console.ReadLine();
		}
	}
}